<template>
	<div class="partnerList">
		<div class="partnerList_top">
			<el-breadcrumb separator-class="el-icon-arrow-right" style="margin-top: 10px;">
				<el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
				<el-breadcrumb-item :to="{ path: '/stewardTeam' }">团队列表</el-breadcrumb-item>
				<el-breadcrumb-item>团队详情</el-breadcrumb-item>
			</el-breadcrumb>
		</div>
		<div class="partnerList_bottom">
			<div class="partnerList_bottom_new">
				<div class="partnerList_bottom_new_goods">
					<div class="partnerList_bottom_new_goods_screening">
                       <!-- <span>卖场：</span>
                        <el-select
                          v-model="info.market_name"
                          clearable
                          @change="selectMarket"
                          filterable
						  disabled 
                          placeholder="卖场"
                        >
                          <el-option
                            v-for="item in marketList"
                            :key="item.id"
                            :label="item.name"
                            :value="item.id"
                          >
                          </el-option>
                        </el-select> -->
						<div class="sidebarLeft item">
							<div style="margin-left: 20px">
							  卖场：<strong style="font-size: 18px">{{info.market_name}}</strong>
							</div>
							<div style="margin-left: 20px">
							  团队名称：<strong style="font-size: 18px">{{info.stewardName}}</strong>
							</div>
							<div style="margin-left: 20px">
							  团队总收益：<strong style="font-size: 18px">{{info.commission}}</strong>
							</div>
							<div style="margin-left: 50px">
							  团队总订单数：<strong style="font-size: 18px">{{info.num}}</strong>
							</div>
						</div>
						<!-- <div class="item">
							<el-input v-model="keyword" placeholder="搜索"></el-input>
						</div>
						<div class="item">
							<button @click="handerSeach" class="searchBtn"><i class="el-icon-search"></i>搜索</button>
						</div> -->
					</div>
				</div>
			</div>
			
			<div class="teamUser">
				<el-button type="primary" size="medium" style="margin-right: 20px" @click="handleAdd">添加管理员
				</el-button>
				<span>订单类型：</span>
				<el-select
				  v-model="partner_type"
				  clearable
				  @change="selectOrder"
				  filterable
				  placeholder="订单类型"
				>
				  <el-option
				    v-for="item in orderType"
				    :key="item.value"
				    :label="item.name"
				    :value="item.value"
				  >
				  </el-option>
				</el-select>
				<span>排序：</span>
				<el-select
				  v-model="orderSort"
				  clearable
				  @change="selectOrderSort"
				  filterable
				  placeholder="排序类型"
				>
				  <el-option
				    v-for="item in sortField"
				    :key="item.value"
				    :label="item.name"
				    :value="item.value"
				  >
				  </el-option>
				</el-select>
				订单日期：
				<el-date-picker
				  style="margin-right: 20px"
				  clearable
				  v-model="valueTime"
				  :picker-options="pickerOptions"
				  type="daterange"
				  @change="selectTime"
				  range-separator="至"
				  start-placeholder="开始日期"
				  end-placeholder="结束日期"
				>
				</el-date-picker>
			</div>
			<div class="partnerList_table">
				
				<div class="partnerList_bottom_table">
					<table>
						<tr>
							<th></th>
							<th>序号</th>
							<th>队员名称</th>
							<th>用户头像</th>
							<th>用户手机</th>
							<th>订单金额</th>
							<th>带单金额</th>
							<th>带客数</th>
							<th>收益</th>
							<th>角色</th>
							<th>消息存档</th>
							<th>企业微信状态</th>
							<th>创建时间</th>
							<th>操作</th>
						</tr>
						<tr v-for="(v,i) in listData" :key="i">
							<td>
								<font class="checkbox" :class="{'check_active' : checkBoxAll.includes(i)}"
									@click="handlerCheckbox(i)"><i class="el-icon-check"></i></font>
							</td>
							<td>{{v.id}}</td>
							<td>
								{{v.nickname}}
							</td>
							<td>
								<div style="width: 80px;height: 80px;overflow: hidden;margin:4px auto;">
									<img :src="v.headimg.path" style="width: 100%;height: 100%;">
								</div>
							</td>
							<td>
								{{v.mobile}}
							</td>
							<td>{{v.order_amount}}</td>
							<td>{{v.amount}}</td>
							<td>{{v.num}}</td>
							<td>{{v.commission}}</td>
							<td>{{v.type==1?'超级管家':v.type==2?'超级政委':'精英管家'}}</td>
							<td>{{v.is_msg_audit==1?'开启':'关闭'}}</td>
							<td>
								{{qywx_status[v.qywx_status]}}
							</td>
							<td>
								<template v-if="v.create_time">
									{{v.create_time}}
								</template>
								<template v-else>
									---
								</template>
							</td>
							
							<td>
								<button class="editor shelves" @click="goDetails(v.steward_id,v.user_id)">成员详情</button>
								<button class="editor delete" @click="deletes(v.steward_id,v.user_id)">删除成员</button>
							</td>
						</tr>
						<tr v-if="listData.length == 0">
							<td class="table_title" colspan="10">当前数据空空如也</td>
						</tr>
					</table>
					<div class="partnerList_bottom_page">
						<div class="partnerList_bottom_page_left">
							<div class="partnerList_bottom_page_left_checkAll" @click="handerCheckAll">
								<font class="checkbox" :class="{'check_active' : checkAll}"><i
										class="el-icon-check"></i></font>
							</div>全选
							<!-- <button class="partnerList_bottom_page_left_btn" @click="selectDel">删除</button> -->
						</div>
						<div class="partnerList_bottom_page_right">
							<el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
								:current-page="page" :page-sizes="[10, 20, 30, 40]" :page-size="pageSize"
								layout="total, sizes, prev, pager, next, jumper" :total="total" background>
							</el-pagination>
						</div>
					</div>
				</div>
			</div>
			<!-- 新增团队成员 -->
			<modal :title="MadalTitle" v-model="visibleShow" :centered="true" :maskClosable="false" @ok="teamUser"
				@cancel="handleCancel">
				<div>
					<el-form ref="ruleForm" label-width="100px" class="demo-ruleForm">
						<el-form-item label="卖场" prop="name">
							<el-input type="text" v-model="info.market_name" placeholder="" />
						</el-form-item>
						<el-form-item label="选择用户" prop="nickname">
							<el-select v-model="mobile" filterable placeholder="请选择">
								<el-option v-for="item in storeList" :key="item.mobile" :label="item.mobile"
									:value="item.mobile">
								</el-option>
							</el-select>
						</el-form-item>
						<el-form-item label="手机号码" prop="name">
							<el-input type="text" v-model="mobile" :disabled="true" placeholder="手机号码" />
						</el-form-item>
						<el-form-item label="选择类型" prop="name">
							<el-select v-model="type" filterable placeholder="请选择">
								<el-option v-for="item in typeList" :key="item.id" :label="item.name"
									:value="item.id">
								</el-option>
							</el-select>
						</el-form-item>
					</el-form>
				</div>
			</modal>
			</div>
			</div>
</template>

<script>
	import modal from 'ant-design-vue/lib/modal';
	import 'ant-design-vue/lib/table/style/css'; // 或者 ant-design-vue/lib/button/style/css 加载 css 文件
	import 'ant-design-vue/lib/modal/style/css'; // 或者 ant-design-vue/lib/button/style/css 加载 css 文件
	export default {
		components: {
			modal
		},
		data() {
			return {
				listData: [],
				keyword: '',
				cate: {},
				input: '',
				checkAll: false,
				page: 1,
				pageSize: 20,
				pageSizes:10000,
				total: 0,
				checkBoxAll: [], // 选中的数据
				shelvesAlls: [],
				tableList: [],
				status: 1, //团队状态
				visibleShow: false,
				merchantShow: false, //编辑窗口显示
				dialogVisible: false,
				dialogImageUrl: "", //图片
				fileList: [],
				title: '', //团队标题
				sub_title: '', //团队副标题
				steward_id:'',//团队id
				MadalTitle: '',
				activity_id: '', //活动id
				market_id: '', //卖场
				typeList: [
					{
						name:'超级管家',
						id:1
					},
					{
						name:'超级政委',
						id:2
					}
				], //活动列表
				activityKeyword: '', //活动搜索
				userList: [], //商户列表
				choose_id:'',//选择的用户
				steward_id:'',//团队id
				edit:false,//是否编辑
				marketList: [],
				marketId:'',//选择搜索的卖场id
				storeList:[],
				type:'',
				info:{},
				mobile:'',//选择的用户
				qywx_status:{
					1:'已激活',
					2:'已禁用',
					4:'未激活',
					5:'退出企业'
				},
				partner_type:'',
				//订单类型
				orderType:[
					{
						'name':'普通订单',
						'value':'shop',
					},
					{
						'name':'产品包',
						'value':'pack',
					},
					{
						'name':'施工单',
						'value':'builder',
					},
					{
						'name':'设计单',
						'value':'designer',
					}
				],
				 valueTime: [],
				 pickerOptions: {
				   disabledDate(time) {
				     return time.getTime() > Date.now() - 8.64e6;
				   },
				 },
				 startDate:'',
				 endDate:'',
				 orderSort:'amount',
				 sortField:[
					{
						'name':'订单金额排序',
						'value':'amount',
					},
					{
						'name':'订单数排序',
						'value':'count',
					}
				 ]
			}
		},
		mounted(options) {
			let data = this.$route.query;
			this.steward_id = data.id
			//团队列表
			this.getListAll();
			this.remoteMethod();
		},

		methods: {
			
			 handleSelect(item) {
			        console.log(item);
			      },
			// 获取卖场列表
			remoteMethod() {
			  this.$http.post("/api/root/Market/marketList").then((res) => {
			    if (res.code == 1) {
			      this.marketList = res.data ? res.data : [];
			    }
			  });
			},
			// 选择卖场
			selectMarket() {
			  this.getList(this.marketId);
			},
			
			handleAdd() {
				this.MadalTitle = "添加成员";
				this.visibleShow = true;
				this.getUserList();
			},
			//获取团队成员
			getListAll(){
				let params = {
					//keyword:this.keyword,
					steward_id: this.steward_id,
					page: this.page,
					pageSize: this.pageSize,
					partner_type:this.partner_type,
					start_time:this.startDate,
					end_time:this.endDate,
					order:this.orderSort,
				}
				let that = this;
				that.$http.post('/api/root/steward/view', params).then(res => {
					if (res.code === 1) {
						var data = res.data.userList.list
						that.info=res.data
						if (data.length > 0) {
							that.total = res.data.userList.count
							that.listData = data
						} else {
							that.total = 0
							that.listData = []
						}
					} else {
						that.$message.error(res.msg)
					}
				}).catch(err => {
					that.$message.error(err.msg)
				})
			},
			// 选择时间
			selectTime() {
			  this.startDate = this.valueTime
			    ? this.$moment(this.valueTime[0]).format("yyyy-MM-DD HH:HH:HH")
			    : "";
			  this.endDate = this.valueTime
			    ? this.$moment(this.valueTime[1]).format("yyyy-MM-DD 23:59:59")
			    : "";
			  this.getListAll();
			},
			selectOrder(){
				this.getListAll();
			},
			selectOrderSort(){
				this.getListAll();
			},
			//获取用户
			getUserList(){
				let params = {
					keyword:'',
					page:1,
					market_id:this.info.market_id,
					pageSize:this.pageSizes
				}
				let that = this;
				that.$http.post('/api/root/steward/searchUser', params).then(res => {
					if (res.code === 1) {
						let data = res.data.list
						if (data.length > 0 || res.code===1) {
							that.storeList = data
							
						} else {
							that.storeList = []
						}
					} else {
						that.$message.error(res.msg)
					}
				}).catch(err => {
					that.$message.error(err.msg ? err.msg : err.toString())
				})
			},
			// 图片上传
			handleRemove(file, fileList) {
				this.fileList = fileList;
			},
			handlePictureCardPreview(file) {
				this.dialogImageUrl = file.url;

				this.dialogVisible = true;
			},
			handleExceed(files, fileList) {
				this.$message.warning(`当前限制上传一张图片,请先删除原图片`);
			},
			handleAvatarSuccess(res, file, fileList) {
				this.fileList = fileList;
			},
			beforeAvatarUpload(file) {
				const isLt2M = file.size / 1024 / 1024 < 2;
				if (!isLt2M) {
					this.$message.error("上传商品图片大小不能超过 2MB!");
				}
				return isLt2M;
			},
			getHMS(time) {
				const hour = parseInt(time / 3600) < 10 ? '0' + parseInt(time / 3600) : parseInt(time / 3600)
				const min = parseInt(time % 3600 / 60) < 10 ? '0' + parseInt(time % 3600 / 60) : parseInt(time % 3600 / 60)
				const sec = parseInt(time % 3600 % 60) < 10 ? '0' + parseInt(time % 3600 % 60) : parseInt(time % 3600 % 60)
				return hour + ':' + min + ':' + sec
			},
			
			//添加商户
			addMerchant(id) {
				this.MadalTitle = "添加商户"
				this.merchantShow = true
				this.steward_id=id;//团队id
				
			},
			//删除团队成员
			deletes(steward_id,choose_id){
				let params = {
					steward_id:steward_id,//管家团队id
					choose_id:choose_id,//用户id
				}
				let that = this;
				this.$confirm('是否删除团队成员', '提示').then(() => {
				that.$http.post('/api/root/steward/del', params).then(res => {
					if (res.code === 1) {
						that.$message.success('操作成功')
						that.getListAll();
					} else {
						that.$message.error(res.msg)
					}
				}).catch(err => {
					that.$message.error(err.msg ? err.msg : err.toString())
				})
				})
			},
			handleCancel() {
				this.MadalTitle = ''
				this.dialogVisible = false
				this.visibleShow = false
				this.fileList=[];
			},
			//隐藏弹窗
			storeCancel(){
				this.MadalTitle = ''
				this.merchantShow = false
			},
			
			// 选择状态
			selectStatus() {
				this.page = 1
				this.getShareList(this.room_id)
			},
			//添加团队成员
			teamUser(){
				let array=this.storeList;
				let user_arr ={};
				array.forEach((item,index) => { 
				    if(item.mobile==this.mobile){
						user_arr=item
					}
				});
				let params={
					steward_id:this.steward_id,
					type:this.type,
					choose_id:user_arr.user_id,
				}
				if(this.type==''){
					this.$message.error('请先选择角色权限')
					return;
				}
				this.$http.post('/api/root/steward/add', params).then(res => {
					if (res.code === 1) {
						this.$message.success('操作成功')
						this.getListAll();
					} else {
						this.$message.error(res.msg)
					}
				}).catch(err => {
					this.$message.error(err.msg ? err.msg : err.toString())
				})
			},
			// 多选
			handlerCheckbox(i) {
				console.log(i);
				let arr = this.checkBoxAll;
				if (arr.includes(i)) {
					let index = arr.indexOf(i);
					if (index != -1) {
						arr.splice(index, 1);
						this.shelvesAlls.splice(index, 1);
						if (this.checkBoxAll.length !== this.tableList.length) {
							this.checkAll = false;
						}
					}
				} else {
					this.checkBoxAll.push(i);
					this.shelvesAlls.push(this.tableList[i].id);
					if (this.checkBoxAll.length == this.tableList.length) {
						this.checkAll = true;
					}
				};
				console.log(this.shelvesAlls);
			},
			// 全选与全不选
			handerCheckAll() {
				this.checkAll = !this.checkAll;
				let arr = this.tableList.length;
				this.checkBoxAll = [];
				this.shelvesAlls = [];
				if (this.checkAll) {
					for (let i = 0; i < arr; i++) {
						this.checkBoxAll.push(i);
					}
					this.checkBoxAll.map(v => {
						this.shelvesAlls.push(this.tableList[v].id.toString());;
					})
				} else {
					this.checkBoxAll = [];
					this.shelvesAlls = []
				}
				console.log(this.shelvesAlls);
			},
			//搜索
			handerSeach() {
              this.getListAll()
			},

			handleSizeChange(val) {
				this.pageSize = val;
				this.getListAll()
			},
			handleCurrentChange(val) {
				this.page = val;
				this.getListAll()
			},
			formatDate(value) {
				let date = new Date(parseInt(value) * 1000);
				let y = date.getFullYear();
				let m = date.getMonth() + 1;
				m = m < 10 ? "0" + m : m;
				let d = date.getDate();
				d = d < 10 ? "0" + d : d;
				let h = date.getHours();
				h = h < 10 ? "0" + h : h;
				let minute = date.getMinutes();
				let second = date.getSeconds();
				minute = minute < 10 ? "0" + minute : minute;
				second = second < 10 ? "0" + second : second;
				return y + "-" + m + "-" + d + " " + h + ":" + minute + ":" + second;
			},
			//商户列表跳转
			teamDateils(id){
				this.$router.push({
				  name: "teamDateils",
				  query: {id},
				});
			},
			goDetails(steward_id,user_id){
				this.$router.push({
				  name: "teamUserDateils",
				  query: {steward_id,user_id},
				});
			}
		}
	}
</script>

<style lang="less" scoped>
	@import 'index.less';

	.partnerList_bottom_new_goods_screening {
		width: 100%;
		height: auto;
		display: flex;

		.searchBtn {
			max-width: 90px;
			min-width: 68px;
			height: 42px;
			line-height: 42px;
			background-color: #409EFF;
			margin-left: 5px;
			border: 0 none;
			outline: none;
			border-radius: 4px;
			color: #fff;
			cursor: pointer;
		}

		.inputBox {
			margin-right: 20px;
		}
	}
</style>
<style>
	.ant-modal{
		width: 590px !important;
	}
</style>
